package com.xunk.equipment.service.mandun.vo;

import com.xunk.common.core.annotation.EnumCheck;
import com.xunk.common.core.interfaces.EnumValidateInterface;
import lombok.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;

/**
 * @ProjectName: HIM
 * @Package: com.xunk.equipment.service.mandun.vo
 * @ClassName: IntervalRequest
 * @Author: luanzhiwei
 * @Description: 曼顿查询区间电量请求实体类
 * @Date: 2021/4/13 9:08
 * @Version: 1.0
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
@ToString
public class IntervalRequest {
    /**
     * 设备id
     */
    @NotBlank(message = "设备id不能为空")
    private String deviceSn;

    /**
     * 查询类型，day,month,quarterYear,halfYear,year
     */
    @NotEmpty(message = "查询类型不能为空")
    @EnumCheck(enableClass = IntervalType.class, message = "查询类型为错误的枚举值")
    private String type;

    /**
     * 类型枚举
     */
    public enum IntervalType implements EnumValidateInterface {
        DAY("day", "近一天"),
        MONTH("month", "近一个月"),
        SEASON("season", "近三个月"),
        HALF_YEAR("halfYear", "近半年"),
        YEAR("year", "近一年");
        private String code;
        private String desc;

        IntervalType() {
        }

        IntervalType(String code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public String getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }

        /**
         * 判断是否是可用枚举
         *
         * @param code
         * @return
         */
        @Override
        public Boolean isValidEnum(String code) {
            for (IntervalType value : IntervalType.values()) {
                if (value.getCode().equals(code)) {
                    return true;
                }
            }
            return false;
        }

        /**
         * 查询枚举
         *
         * @param code
         * @return
         */
        public static IntervalType getIntervalType(String code) {
            for (IntervalType value : IntervalType.values()) {
                if (value.getCode().equals(code)) {
                    return value;
                }
            }
            return null;
        }
    }

}
